package cn.juque.systemservice.task;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.juque.systemservice.cache.GenInfoCache;
import cn.juque.systemservice.entity.GenInfo;
import cn.juque.systemservice.mapper.GenInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>GenRefreshQueueTask</li>
 * </ul>
 * @date 2023-01-25 09:37:49
 **/
@Service("genRefreshQueueTask")
public class GenRefreshQueueTask {

    @Resource
    private GenInfoCache genInfoCache;

    @Resource
    private GenInfoMapper genInfoMapper;

    public void execute(){
        List<GenInfo> list = this.genInfoMapper.selectGenList(new GenInfo());
        list.forEach(f-> {
            String dateStr = null;
            if(CharSequenceUtil.isNotEmpty(f.getDateFormat())) {
                dateStr = DateUtil.format(new Date(), f.getDateFormat());
            }
            this.genInfoCache.loadForCache(f.getGenPrefix(),dateStr);
        });
    }
}
